﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Windows;

namespace Organizer
{
    public class Task
    {
        private bool run;
        public bool isRun
        {
            get { return run; }
            set { run = value; }
        }

        private bool active;
        public bool isActive
        {
            get { return active; }
            set { active = value; }
        }

        #region data

        private int pid;
        public int id
        {
            get { return pid; }
            set { pid = value; }
        }

        private string pname;
        public string name
        {
            get { return pname; }
            set { pname = value; }
        }

        private string pdefinition;
        public string definition
        {
            get { return pdefinition; }
            set { pdefinition = value; }
        }

        private DateTime pstartDate;
        public DateTime startDate
        {
            get { return pstartDate; }
            set { pstartDate = value; }
        }

        private DateTime pendDate;
        public DateTime endDate
        {
            get { return pendDate; }
            set { pendDate = value; }
        }

        private int phours;
        public int hours
        {
            get { return phours; }
            set { phours = value; }
        }

        private int pmins;
        public int mins
        {
            get { return pmins; }
            set { pmins = value; }
        }

        private int pspendHour;
        public int spendHour
        {
            get { return pspendHour; }
            set { pspendHour = value; }
        }

        private int pspendMin;
        public int spendMin
        {
            get { return pspendMin; }
            set { pspendMin = value; }
        }

        private int pspendSec;
        public int spendSec
        {
            get { return pspendSec; }
            set { pspendSec = value; }
        }
        
#endregion

        public override string ToString()
        {
            return name;
        }

        public DateTime StartTime = System.DateTime.Now;
        private DateTime EndTime;
        
        public Task()
        {
            name = "";
            definition = "";
            startDate = DateTime.Now;
            endDate = DateTime.Now;
            hours = 0;
            mins = 0;
            spendHour = 0;
            spendMin = 0;
            spendSec = 0;
            isRun = false;

            isActive = true;
        }
        public Task(int Id,DateTime StartDate, DateTime EndDate, string Name, string Definition, int Hours, int Mins, int SpendHours, int SpendMins, int SpendSec ) 
        {
            id = Id;
            name = Name;
            definition = Definition;
            startDate = StartDate;
            endDate = EndDate;
            hours = Hours;
            mins = Mins;
            spendHour = SpendHours;
            spendMin = SpendMins;
            spendSec = SpendSec;
            isRun = false;

            isActive = true;

        }
        ~Task()
        {
            //wtf?
        }

        public void StartTask()
        {
            StartTime = System.DateTime.Now;
            isRun = true;
        }
        public void PauseTask()
        {
            EndTime = System.DateTime.Now;
            isRun = false;
            CalcTime();
        }
        public void CompleteTask()
        {
            EndTime = System.DateTime.Now;
            isRun = false;
            isActive = false;
            CalcTime();
        }

        public void DeleteTask()
        {
            // magic!
            //delete something
        }
        public void EditTask(DateTime StartDate, DateTime EndDate, string Name, string Definition, int Hours, int Mins)
        {
            name = Name;
            definition = Definition;
            startDate = StartDate;
            endDate = EndDate;
            hours = Hours;
            mins = Mins;
        }
        private void CalcTime()
        {
            TimeSpan delta = EndTime.Subtract(StartTime);
            spendHour += delta.Hours;
            spendMin += delta.Minutes;
            spendSec += delta.Seconds;
            if (spendSec > 60)
            {
                spendSec = 0;
                spendMin += 1;
            }
            if (spendMin > 60)
            {
                spendMin = 0;
                spendHour += 1;
            }

        }

    }
}
